package com.kuaiditu.assistant.module.retrofit.impl;

import com.alibaba.fastjson.JSON;
import com.kuaiditu.assistant.api.kdy_api.base.BaseSTRequest;
import com.kuaiditu.assistant.api.kdy_api.base.BaseSTResponse;
import com.kuaiditu.assistant.module.retrofit.ConverterAdapter;
import com.kuaiditu.assistant.util.LogUtil;

import java.io.IOException;

/**
 * Created by Eenie on 2017/9/15.
 * Email: eeniework@gmail.com
 * Des:
 */

public class STConverterAdapter implements ConverterAdapter<BaseSTRequest,BaseSTResponse> {
    @Override
    public String onConverterRequest(BaseSTRequest request) throws IOException {

        LogUtil.e(request.toString());

        return request.toString();
    }

    @Override
    public String onConverterResponse(BaseSTResponse response) throws IOException {
        if (response.isSuccess()) {
            return JSON.toJSONString(response);
        } else {
            throw new IOException(response.getMsg());
        }
    }

    @Override
    public BaseSTResponse strToObj(String str) {

        LogUtil.e(str);

        return JSON.parseObject(str, BaseSTResponse.class);
    }
}
